home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Miscellaneous / gdbm / README < prev    next >
Text File  |  1992-04-05  |  14KB  |  400 lines

  1. This is release 1.5 of GNU dbm.  Better documentation will be written
  2. soon.  For now, this file briefly describes the contents of this
  3. release and how to use it.
  4.  
  5. The files are:
  6.  
  7. COPYING        - Copying information.
  8. README        - This file.
  9.  
  10. bucket.c, extern.h, falloc.c, findkey.c, gdbm.proto, gdbmclose.c,
  11. gdbmconst.h gdbmdefs.h, gdbmdelete.c, gdbmerrno.h, gdbmfetch.c,
  12. gdbmopen.c, gdbmreorg.c, gdbmseq.c, gdbmstore.c, global.c, gndbm.h,
  13. hash.c systems.h, update.c, version.c - Source for GNU dbm library.
  14.  
  15. dbm.h dbminit.c, delete.c, fetch.c, seq.c, store.c - Source for the
  16. DBM interface.
  17.  
  18. dbmclose.c, dbmdelete.c, dbmdirfno.c, dbmfetch.c, dbmopen.c, dbmpagfno.c
  19. dbmseq.c, dbmstore.c, ndbm.h - Source for the NDBM interface.
  20.  
  21. Makefile     - Makefile, will make gdbm.a  (BSD and SYSV)
  22. testgdbm.c    - A simple test program.
  23. testdbm.c    - A simple test program.
  24. testndbm.c    - A simple test program.
  25. conv2gdbm.c    - A dbm database conversion program.
  26.  
  27. CHANGES from 1.4 to 1.5:
  28.   1.  Minor bug fixes.  See the ChangeLog.
  29.   2.  Added gdbmconst.h to allow users to change the size of the
  30.       bucket cache in the systems.h file.
  31.  
  32. CHANGES from 1.0 to 1.4:
  33.   1.  Mainly bug fixes.
  34.   2.  A define for "dbmclose()" was added to dbm.h for those few 
  35.       implementaions that need that call.
  36.   3.  For details, see the ChangeLog.
  37.  
  38. CHANGES from 0.9 to 1.0:
  39.   1.  Makefiles were combined into one and a few new things added to it.
  40.   2.  Several minor bugs were fixed including a cache bug.
  41.   3.  Two new calls (dbm_pagfno, dbm_dirfno) were added to the NDBM interface.
  42.   3.  A conversion program from dbm files to gdbm files was added.
  43.   4.  Reorganize was changed to allow complex file names. (dir/file form)
  44.   5.  testgdbm, testndbm, and testdbm were modified to return key and data
  45.       pairs where needed and to take an optional file name as an argument.
  46.       testgdbm had some command characters changed.
  47.   6.  The DBM and NDBM interfaces were separated.
  48.   7.  An include file for dbm users was added. (dbm.h)
  49.   8.  The include file for ndbm users was renamed ndbm.h. (It was gndbm.h.)
  50.  
  51. CHANGES from 0.8 to 0.9:
  52.   1.  The hash function changed.
  53.   2.  The file format changed.
  54.   3.  There was a complete rewrite of falloc.c.
  55.   4.  There were added compatiblity routines for ndbm.
  56.   5.  The file names for dbm compatibility routines were made to
  57.       look like dbm.
  58.   6.  Test programs changed.
  59.   7.  Support for System V.
  60.   8.  Various other small changes.
  61.   9.  The need for recovery and associated code was removed.
  62.  
  63.  
  64. GNU dbm is a set of database routines that use extendible hashing and
  65. works similar to the standard UNIX dbm routines.  The basic unit of
  66. data is the structure
  67.  
  68.   typedef struct {
  69.              char *dptr;
  70.              int   dsize;
  71.           } datum;
  72.  
  73. The following is a quick list of the routines.  After this list, a
  74. longer description of each routine will be given.  An include file
  75. will be produced that can be included by the user. The file is
  76. "gdbm.h".  The following routines are defined in terms of gdbm.h:
  77.  
  78.   GDBM_FILE gdbm_open ( name, block_size, read_write, mode, fatal_func )
  79.  
  80.   void gdbm_close ( dbf )
  81.   
  82.   int gdbm_store ( dbf, key, content, flags )
  83.  
  84.   datum gdbm_fetch ( dbf, key )
  85.  
  86.   int gdbm_delete ( dbf, key )
  87.  
  88.   datum gdbm_firstkey ( dbf )
  89.  
  90.   datum gdbm_nextkey ( dbf, key )
  91.  
  92.   int gdbm_reorganize ( dbf )
  93.  
  94.  
  95. For compatibility with the standard dbm, the following routines are 
  96. defined.  There is an include file for dbm users called "dbm.h".
  97.  
  98.   int dbminit ( name )
  99.  
  100.   int store ( key, content )
  101.  
  102.   datum fetch ( key )
  103.  
  104.   int delete ( key )
  105.  
  106.   datum firstkey ()
  107.  
  108.   datum nextkey ( key )
  109.  
  110.  
  111. There are also compatibility routines for ndbm.  For ndbm compatiblity
  112. routines, you need the include file "ndbm.h".  The routines are:
  113.  
  114. DBM *dbm_open (name, flags, mode)
  115.  
  116. void dbm_close (file)
  117.  
  118. datum dbm_fetch (file, key)
  119.  
  120. int dbm_store (file, key, content, flags)
  121.  
  122. int dbm_delete (file, key)
  123.  
  124. datum dbm_firstkey (file)
  125.  
  126. datum dbm_nextkey (file)
  127.  
  128. int dbm_error (file)
  129.  
  130. int dbm_clearerr (file)
  131.  
  132. int dbm_pagfno (file)
  133.  
  134. int dbm_dirfno (file)
  135.  
  136.  
  137. Description of GNU dbm routines.
  138. --------------------------------
  139.  
  140. GNU dbm allows multiple data files.  A routine that opens a gdbm file
  141. is designated as a "reader" or a "writer".  Only one writer may open a
  142. gdbm file and many readers may open the file.  Readers and writers can
  143. not open the gdbm file at the same time. The procedure for opening a
  144. gdbm file is:
  145.  
  146. GDBM_FILE dbf;
  147.  
  148. dbf = gdbm_open ( name, block_size, read_write, mode, fatal_func )
  149.  
  150. The parameters are:
  151.   char *name - the name of the file (the complete name, gdbm does
  152.       not append any characters to this name)
  153.   int block_size - the size of a single transfer from disk to memory.
  154.       This parameter is ignored unless the file is a new file.
  155.       The minimum size is 512.  If it is less than 512, dbm will
  156.       use the stat block size for the file system.
  157.   int read_write - 0 => reader, 1 => writer, 2 => writer (if the database
  158.       does not exist, create a new one, 3 => writer and create a new
  159.       database regardless if one exists.  (Defined in gdbm.h as
  160.       GDBM_READER, GDBM_WRITER, GDBM_WRCREAT, GDBM_NEWDB.)
  161.   int mode - file mode (see chmod(2) and open(2)) if the file is created.
  162.   void (*fatal_func) () - a function for dbm to call if it detects a
  163.       fatal error. The only parameter of this function is a string.
  164.       If the value of 0 is provided, gdbm will use a default function.
  165.  
  166. The return value, dbf, is the pointer needed by all other routines to
  167. access that gdbm file.  If the return is the NULL pointer, gdbm_open
  168. was not successful.  The errors can be found in "gdbm_errno" for gdbm
  169. errors and in "errno" for file system errors.  (For error codes, see
  170. gdbmerrno.h.)
  171.  
  172. In all of the following calls, the parameter "dbf" refers to the pointer
  173. returned from gdbm_open.
  174.  
  175. It is important that every file opened is also closed.  This is needed to
  176. update the reader/writer count on the file.  This is done by:
  177.  
  178.   gdbm_close(dbf);
  179.  
  180.  
  181. The database is used by 3 primary routines.  The first stores data in the
  182. database.
  183.  
  184.   ret = gdbm_store ( dbf, key, content, flag )
  185.  
  186.   The parameters are:
  187.      char *dbf - the pointer returned by gdbm_open
  188.      datum key - the key data
  189.      datum content - the data to be associated with the key
  190.      int   flag - 0 => insert only, generate an error if key exists.
  191.               1 => replace contents if key exists.  (Defined in
  192.               gdbm.h as GDBM_INSERT and GDBM_REPLACE.)
  193.  
  194.   If a reader calls store, ret gets -1.  If called with GDBM_INSERT and
  195.   key is in the database, ret gets 1.  Otherwise, ret is 0.
  196.   NOTICE: If you store data for a key that is already in the data base,
  197.   gdbm replaces the old data with the new data if called with GDBM_REPLACE.
  198.   You do not get two data items for the same key and you do not get an
  199.   error from gdbm_store.
  200.   NOTICE: The size in gdbm is not restricted like dbm or ndbm.  Your data
  201.   can be as large as your "want".
  202.   NOTICE: Both key and content must have the dptr field be a non-NULL
  203.   value.  Since a NULL dptr field is used by other routines to indicate an
  204.   error, a NULL field cannot be valid data.  If either key or content have
  205.   a null dptr field, gdbm_open will return an error.
  206.  
  207. To search for some data:
  208.  
  209.   content = gdbm_fetch ( dbf, key )
  210.  
  211.   The parameters are:
  212.      char *dbf - the pointer returned by gdbm_open
  213.      datum key - the key data
  214.  
  215.   The "datum" returned in content is a pointer to the data found.  If the
  216.   dptr is NULL, no data was found.  If dptr is not NULL, then it points
  217.   to data allocated by malloc.  gdbm does not automatically free this data.
  218.   The user must free this storage when done using it.  This eliminates the
  219.   need to copy the result to save it for later use. (You just save the 
  220.   pointer.)
  221.  
  222. To remove some data from the database:
  223.  
  224.   ret = gdbm_delete ( dbf, key )
  225.  
  226.   The parameters are:
  227.      char *dbf - the pointer returned by gdbm_open
  228.      datum key - the key data
  229.  
  230.   The ret value is -1 if the item is not present or the requester is a reader.
  231.   The ret value is 0 if there was a successful delete.
  232.  
  233.  
  234. The next two routines allow for accessing all items in the database.  This 
  235. access is not key sequential, but it is guaranteed to visit every key in
  236. the database once.  (The order has to do with the hash values.)
  237.  
  238.   key = gdbm_firstkey ( dbf )
  239.  
  240.   nextkey = gdbm_nextkey ( dbf, key )
  241.  
  242.   The parameters are:
  243.      char *dbf - the pointer returned by gdbm_open
  244.      datum key - the key data
  245.  
  246.   The return values are both datum.  If key.dptr or nextkey.dptr is NULL,
  247.   there is no first key or next key.  Again notice that dptr points to
  248.   data allocated by malloc and gdbm will not free it for you. 
  249.  
  250. The following routine should be used very seldom.  
  251.   
  252.   ret = gdbm_reorganize ( dbf )
  253.  
  254.   If you have had a lot of deletions and would like to shrink the space
  255.   used by the gdbm file, the this routine will reorganize the database.
  256.   gdbm will not shorten the length of a gdbm file except by using this
  257.   reorganization.  (Deleted file space will be reused.)
  258.  
  259.  
  260. The following two are variables that may need to be used:
  261.  
  262.   gdbm_error gdbm_errno   -   the variable that contains more information
  263.                               about gdbm errors.  ( gdbm.h has the
  264.                   definitions of the error values. )
  265.  
  266.   char * gdbm_version     -   the string containing the version information.
  267.  
  268.  
  269. There are a few more things of interest.  First, gdbm files are not
  270. "sparse".  You can copy them with the UNIX cp command and they will
  271. not expand in the copying process.  Also, there is a compatibility
  272. mode for use with programs that already use UNIX dbm.  In this
  273. compatibility mode, no gdbm file pointer is required by the user.
  274. Only one file may be opened at a time.  All users in compatibility
  275. mode are assumed to be writers.  If the gdbm file is a read only, it
  276. will fail as a writer, but will also try to open it as a reader.  All
  277. returned pointers in datum structures point to data that gdbm WILL
  278. free.  They should be treated as static pointers (as standard UNIX dbm
  279. does).  The compatibility routine names are the same as the UNIX dbm
  280. routine names.  Their definitions follow:
  281.  
  282.   int dbminit ( name )
  283.  
  284.   int store ( key, content )
  285.  
  286.   datum fetch ( key )
  287.  
  288.   int delete ( key )
  289.  
  290.   datum firstkey ()
  291.  
  292.   datum nextkey ( key )
  293.  
  294. NOTE: Some implementations have an include file "dbm.h".  That file is just
  295. a file that defines datum and the above routines.  Many original dbm 
  296. sites do not have a "dbm.h" file.  One is included here for those who 
  297. want it.
  298.  
  299. WARNING: standard UNIX dbm and GNU dbm do not have the same data format in the
  300. file.  You cannot access a standard UNIX dbm file with GNU dbm!  If you want
  301. to use an old database with GNU dbm, you must use the convert program.
  302.  
  303. Also, GNU dbm has compatibility routines for ndbm.  For ndbm compatiblity
  304. routines, you need the include file "ndbm.h".  
  305.  
  306. WARNING: If you have ndbm and gdbm, there is a conflict in the names of the
  307. include file for the ndbm interface and the original ndbm package.  Do not
  308. blindly copy "ndbm.h" to your include directory.
  309.  
  310. The routines are:
  311.  
  312.     DBM *dbm_open (name, flags, mode)
  313.  
  314.     void dbm_close (file)
  315.  
  316.     datum dbm_fetch (file, key)
  317.  
  318.     int dbm_store (file, key, content, flags)
  319.  
  320.     int dbm_delete (file, key)
  321.  
  322.     datum dbm_firstkey (file)
  323.  
  324.     datum dbm_nextkey (file)
  325.  
  326.     int dbm_error (file)
  327.  
  328.     int dbm_clearerr (file)
  329.  
  330.     int dbm_dirfno (file)
  331.  
  332.     int dbm_pagfno (file)
  333.  
  334. Again, just like ndbm, any returned datum can be assumed to be static
  335. storage.  You do not have to free that memory, the ndbm compatibility
  336. routines will do it for you.
  337.  
  338.  
  339. Notes on making GNU dbm.
  340. ------------------------
  341.  
  342. The "Makefile" will make both "gdbm.a", the collection of gdbm routines and
  343. three simple test programs that uses the gdbm routines.  Two test programs
  344. test the dbm and the ndbm interface routines.  The third was use to help
  345. debug gdbm and contains "inside knowledge."   The first two can be linked
  346. using the original dbm and ndbm routines.  The makefile also makes the
  347. conversion program, conv2gdbm.   The make commands are:
  348.  
  349.    make gdbm.a        makes the gdbm.a archive.
  350.    make testgdbm    makes both gdbm.a and the gdbm test program.
  351.    make testdbm     makes both gdbm.a and the dbm test program with gdbm.
  352.    make testndbm    makes both gdbm.a and the ndbm test program with gdbm.
  353.    make allgdbm        makes all of the above.
  354.    make tdbm        makes the dbm test program linked with dbm, not gdbm.
  355.    make tndbm        makes the ndbm test program linked with ndbm, not gdbm.
  356.    make alldbm        makes the two previous programs.
  357.    make conv2gdbm    makes the conversion program.
  358.    make all        makes all the above.
  359.    make install        installs gdbm.a as /usr/lib/libgdbm.a and gdbm.h.
  360.  
  361.  
  362. CONV2GDBM
  363. ---------
  364.  
  365. The program conv2gdbm has been provided to help you convert from dbm
  366. databases to gdbm.  The usage is:
  367.  
  368.    conv2gdbm [-q] [-b block_size] dbm_file [gdbm_file]
  369.  
  370. The optional "block_size" is the same as in gdbm_open.  The dbm_file is
  371. the name of the dbm file without the .pag or .dir extensions.  The
  372. optional gdbm_file is the complete file name.  If not included, the
  373. gdbm file name is the same as the dbm file name without any extensions.
  374. That is "conv2gdbm dbmfile" converts the files "dbmfile.pag" and
  375. "dbmfile.dir" into a gdbm file called "dbmfile".  The -q option causes
  376. conv2gdbm to work quietly.
  377.  
  378.  
  379. System V support  (And other systems.)
  380. --------------------------------------
  381.  
  382. There is now support for System V.  This done via the systems.h file.
  383. This is the place where all system dependencies should go.  The 
  384. makefile should make gdbm with a few changes.  The makefile describes
  385. the changes necessary for use with System V.  Also, read the makefile
  386. and edit it if you use gcc.  There are several places where changes
  387. are needed to use gcc.
  388.   1)  uncomment: #CC=gcc
  389.   2)  change the lines to make the test programs. (See the comments.)
  390.  
  391. If you port gdbm to another system, try to follow the change style used for
  392. System V changes.  Please send your changes to phil@cs.wwu.edu if you would
  393. like your changes included in a future release of gdbm.
  394.  
  395. Please send bug reports to bug-gnu-utils@prep.ai.mit.edu.
  396.  
  397. Thank you.
  398.  
  399.  
  400.